import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '../views/layout/Layout'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)


/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    menu: 'menu-path'            当前路由需要显示的默认menu对应的path
    isfold: true                 当前路由是否是一个组
  }
**/
export const constantRouterMap = [
  { path: '/login', name: 'login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', name: '404', component: () => import('@/views/404'), hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    name: 'start',
    hidden: true,
    children: [{
      path: 'home',
      name: 'home',
      component: () => import('@/views/dashboard/index')
    }]
  }
]

export const asyncRouterMap = [
  {
    path: '/info',
    name: 'info',
    component: Layout,
    redirect: '/info/carinfo',
    meta: { title: '人/车信息管理', icon: 'peisongyuan' },
    children: [
      {
        path: 'carinfo',
        name: 'carinfo',
        component: () => import('@/views/info/carinfo/carinfo'),
        meta: { title: '车辆基本信息', icon: 'infocar', menu: '/info/carinfo' },
        hidden: true
      },
      {
        path: 'staffinfo',
        name: 'staffinfo',
        component: () => import('@/views/info/staffinfo/staff'),
        meta: { title: '部门员工信息', icon: 'table', menu: '/info/carinfo' },
        hidden: true
      }
    ]
  },
  {
    path: '/maintenance',
    name: 'maintenance',
    component: Layout,
    redirect: '/maintenance/carMaintenance',
    meta: { title: '车辆维保管理', icon: 'pinpai' },
    children: [
      {
        path: 'carMaintenance',
        name: 'carMaintenance',
        component: () => import('@/views/maintenance/carMaintenance/carMaintenance'),
        meta: { title: '车辆维保管理', icon: 'table', menu: '/maintenance/carMaintenance' },
        hidden: true
      }
    ]
  },
  {
    path: '/carcheck',
    name: 'carcheck',
    component: Layout,
    redirect: '/carcheck/checkjudge',
    meta: { title: '车辆测评管理', icon: 'zhibiaochaxun' },
    children: [
      {
        path: 'checkjudge',
        name: 'checkjudge',
        component: () => import('@/views/carcheck/checkjudge/checkjudge'),
        meta: { title: '车辆检测和评定登记表', icon: 'table', menu: '/carcheck/checkjudge' },
        hidden: true
      }
    ]
  },
  {
    path: '/drivecost',
    name: 'drivecost',
    component: Layout,
    redirect: '/drivecost/monthDriveMileageCost',
    meta: { title: '出车费用管理', icon: 'example' },
    children: [
      {
        path: 'monthDriveMileageCost',
        name: 'monthDriveMileageCost',
        component: () => import('@/views/drivecost/monthDriveMileageCost/monthDriveMileageCost'),
        meta: { title: '出车&费用管理', icon: 'table', menu: '/drivecost/monthDriveMileageCost' },
        hidden: true
      }
    ]
  },
  {
    path: '/goodsinout',
    name: 'goodsinout',
    component: Layout,
    redirect: '/goodsinout/goodsout',
    meta: { title: '出入库管理', icon: 'jigui' },
    children: [
      {
        path: 'goodsout',
        name: 'goodsout',
        component: () => import('@/views/goodsinout/goodsout/goodsout'),
        meta: { title: '物资出库表', icon: 'table', menu: '/goodsinout/goodsout' },
        hidden: true
      },
      {
        path: 'goodsin',
        name: 'goodsin',
        component: () => import('@/views/goodsinout/goodsin/goodsin'),
        meta: { title: '物资入库表', icon: 'table', menu: '/goodsinout/goodsout' },
        hidden: true
      },
      {
        path: 'goodscheck',
        name: 'goodscheck',
        component: () => import('@/views/goodsinout/goodscheck/goodscheck'),
        meta: { title: '物资盘点表', icon: 'table', menu: '/goodsinout/goodsout' },
        hidden: true
      }
    ]
  },
  {
    path: '/earlywarningadmin',
    name: 'earlywarningadmin',
    component: Layout,
    redirect: '/earlywarningadmin/details',
    meta: { title: '预警管理', icon: 'lingyongjilu' },
    children: [
      {
        path: 'details',
        name: 'details',
        component: () => import('@/views/earlywarningadmin/details/details'),
        meta: { title: '预警详情', icon: 'table', menu: '/earlywarningadmin/details' },
        hidden: true
      },
      {
        path: 'carmileageconfig',
        name: 'carmileageconfig',
        component: () => import('@/views/earlywarningadmin/carmileageconfig/carmileageconfig'),
        meta: { title: '车辆里程预警配置', icon: 'table', menu: '/earlywarningadmin/details' },
        hidden: true
      },
      {
        path: 'cartimeconfig',
        name: 'cartimeconfig',
        component: () => import('@/views/earlywarningadmin/cartimeconfig/cartimeconfig'),
        meta: { title: '车辆时间预警配置', icon: 'table', menu: '/earlywarningadmin/details' },
        hidden: true
      },
      {
        path: 'personconfig',
        name: 'personconfig',
        component: () => import('@/views/earlywarningadmin/personconfig/personconfig'),
        meta: { title: '人员预警配置', icon: 'table', menu: '/earlywarningadmin/details' },
      }
    ]
  },
  {
    path: '/systemconfigadmin',
    name: 'systemconfigadmin',
    component: Layout,
    redirect: '/systemconfigadmin/systemconfig',
    meta: { title: '系统配置管理', icon: 'nested' },
    children: [
      {
        path: 'systemconfig',
        name: 'systemconfig',
        component: () => import('@/views/systemconfigadmin/systemconfig/systemconfig'),
        meta: { title: '系统配置管理', icon: 'table', menu: '/systemconfigadmin/systemconfig' },
        hidden: true
      }
    ]
  },
  {
    path: '/user',
    name: 'user',
    component: Layout,
    redirect: '/user/userinfo',
    meta: { title: '用户管理', icon: 'user' },
    children: [
      {
        path: 'userinfo',
        name: 'userinfo',
        component: () => import('@/views/user/userinfo/userinfo'),
        meta: { title: '用户信息', icon: 'table', menu: '/user/userinfo' },
        hidden: true
      },
      {
        path: 'auth',
        name: 'auth',
        component: () => import('@/views/user/auth/auth'),
        meta: { title: '用户权限管理', icon: 'table', menu: '/user/userinfo' },
        hidden: true
      }
    ]
  },
  {
    path: '/about',
    name: 'about',
    component: Layout,
    redirect: '/about/aboutus',
    meta: { title: '关于我们', icon: 'about' },
    children: [{
      path: 'aboutus',
      name: 'aboutus',
      component: () => import('@/views/about/aboutus'),
      meta: { title: '关于我们', icon: 'table', menu: '/about/aboutus' },
      hidden: true
    }]
  },
  { path: '*', name: '*', redirect: '/404', hidden: true }
]

const $router = new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

$router.afterEach((to, from) => {
  console.log('进入:'+to.name)
  console.log(to)
  vue.$store.commit('SET_ACTIVE_ROUTE', to.name) // 记录当前路由name
})

export default $router
